var common = require("./common");

// auto define common variable
var evalString = "";
Object.keys(common).forEach((e,i) => {
    evalString += `var ${e} = common.${e};`;
});
if(typeof(evalString) !== "undefined" || evalString !== null){
    eval(evalString);
}

describe("Test the Machine",function (){
    this.timeout(5000);

    it("upload fingerprint should work ok",function(done){
        request
            .post(host + "/uploadFingerPrint")
            .send({fingerprint : [0XCA, 0X11, 0X00, 0X00, 0X60, 0X01, 0X00,
                    0X01, 0X08, 0X07, 0X6D, 0X00, 0X00, 0X00, 0X00, 0X00, 0X4F, 0X41,
                    0X30, 0X30, 0X00]})
            .send({psk : "b3VyZWRh"})
            .send({fingerprint_id : "11"})
            .then(function(res){
                console.log(res.text);
                done();
            });
    });

    it("upload user info should work ok",function(done){
        request
            .post(host + "/uploadUserInfo")
            .send({name : "员工CTO"})
            .send({phone : "18340861711"})
            .send({employee_id : "201490000"})
            .send({psk : "b3VyZWRh"})
            .then(function(res){
                console.log(res.text);
                done();
            });
    });

    it("heartbeat api should work ok", function(done){
        request
            .post(host + "/heartbeat")
            .send({psk : "b3VyZWRh"})
            .then((res) => {
                console.log(res.text);
                done();
            });
    });

    it("complete data api should work ok", function(done){
        request
            .post(host + "/completeData")
            .send({native_lasted_modified_time : "1525402200000"})
            .then((res) => {
                console.log(res.text);
                done();
            });
    });

    it("clockInAndOut should work ok", function(done){
        request
            .post(host + "/clockInAndOut")
            .send({fingerprint_id : "1"})
            .send({clock_time : new Date().getTime()})
            .then((res) => {
                console.log(res.text);
                done();
            });
    });

    // it("delete employee should work ok", function(done){
    //     request
    //         .post(host + "/deleteFingerprint")
    //         .send({fingerprint_id : "11"})
    //         .then((res) => {
    //             console.log(res.text);
    //             done();
    //         });
    // });
});